import 'package:city_corner/main-page/filter-panel/opt-list.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'area-data.dart';

class Area extends StatefulWidget {
  final String cityCode;
  Area({this.cityCode = '4401'});

  @override
  _AreaState createState() => _AreaState();
}

class _AreaState extends State<Area> {
  // 区
  List region = [];

  @override
  void initState() {
    setRegionList();
  }

  void setRegionList() {
    List _region = [];
    areaList['county_list'].forEach((key, value) {
      String _key = key.toString();
      if (_key.substring(0, 4) == widget.cityCode) {
        _region.add({'label': value, 'value': _key});
      }
    });
    setState(() {
      region = _region;
    });
    Map county = areaList['county_list'];
    List opts = [];
    county.forEach((key, value) {
      opts.add({'label': value, 'value': key});
    });
  }

  @override
  Widget build(BuildContext context) {
    return OptList(
      opts: region,
    );
  }
}
